package com.baseframe.auth.config;

import com.baseframe.auth.support.BaseJwtTokenEnhancer;
import com.baseframe.jwt.constant.BaseJwtConstant;
import com.baseframe.jwt.props.BaseJwtProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.TokenEnhancer;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;


@Configuration
public class BaseJwtTokenStoreConfiguration {

    /**
     * jwt令牌
     *
     * @return jwt令牌
     */
    @Bean
    public TokenStore tokenStore() {
        return new JwtTokenStore(jwtAccessTokenConverter());
    }

    /**
     * jwt令牌转换器  将令牌转换成jwt格式
     *
     * @return JwtAccessTokenConverter
     */
    @Bean
    public JwtAccessTokenConverter jwtAccessTokenConverter() {
        JwtAccessTokenConverter jwt = new JwtAccessTokenConverter();
        jwt.setSigningKey(BaseJwtConstant.DEFAULT_SIGN_KEY);
        return jwt;
    }

    @Bean
    public TokenEnhancer jwtTokenEnhancer(BaseJwtProperties baseJwtProperties){

        return new BaseJwtTokenEnhancer(jwtAccessTokenConverter(),baseJwtProperties);
    }

}
